/*LICENSE_BEGIN
 * ******************************************************************
 * All original parts of SoccerScope2003 have copyright (2003) by
 * Team YowAI, represented by Mr. Shuhei Shiota
 * The Department of Creative Informatics
 * The Graduate School of Information Science and Technology
 * The University of Tokyo
 * 
 * Additional classes (except libraries in /lib) were developed by 
 * the Dainamite Robocup-Team of the DAI-Labor, TU-Berlin 
 * (www.dai-labor.de)
 * 
 * Extended/new classes/packages are:
 *   soccerscope.analyzer.LogfileAnalyzer
 *   soccerscope.daistatistic.*
 *   soccerscope.daistatistic.charts.*
 *   soccerscope.daistatistic.tools.*
 *   soccerscope.db.*
 *   soccerscope.dialog.*
 *   soccerscope.model.PlayerWorldModel
 *   soccerscope.model.SimplePlayer
 *   soccerscope.net.AgentConnector
 *   soccerscope.training.*
 *   soccerscope.training.conditions.*
 * ******************************************************************
LICENSE_END*/
package soccerscope.view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics;

import javax.swing.JComponent;

import soccerscope.model.ClientScene;
import soccerscope.model.ColorDB;

public class InfoBar extends JComponent implements ScopeWindow {

	private static final long serialVersionUID = -6126093364978927632L;

	private FontMetrics fm;

	private int margin;

	private ClientScene clientScene;

	public InfoBar(ClientScene clientScene) {
		super();

		this.clientScene = clientScene;
	}

	@Override
	public Dimension getPreferredSize() {
		return getMinimumSize();
	}

	@Override
	public Dimension getMinimumSize() {
		if (this.fm == null) {
			this.fm = this.getFontMetrics(this.getFont());
			this.margin = this.fm.getHeight() / 4;
		}
		return new Dimension(0, this.fm.getHeight() + this.margin * 2);
	}

	public void setScene(ClientScene clientScene) {
		this.clientScene = clientScene;
	}

	@Override
	public void paint(Graphics g) {
		if (this.fm == null) {
			this.fm = this.getFontMetrics(this.getFont());
			this.margin = this.fm.getHeight() / 4;
		}

		if (this.clientScene == null)
			return;

		Dimension d = getSize();
		String s;

		// draw left team name and score
		g.setColor(ColorDB.getColor("team_l_color"));
		g.fillRect(0, 0, d.width / 4, d.height);
		g.setColor(Color.black);
		s = this.clientScene.left.name + " :  " + this.clientScene.left.score;
		g.drawString(s, 0 + this.margin, this.fm.getAscent() + this.margin);

		// draw playmode
		g.setColor(Color.white);
		g.fillRect(d.width / 4, 0, (d.width / 4) * 2, d.height);
		g.setColor(Color.black);
		s = this.clientScene.pmode.toString();
		g.drawString(s, (d.width / 4) * 2 - this.fm.stringWidth(s)
				- this.margin, this.fm.getAscent() + this.margin);

		// draw time
		s = Integer.toString(this.clientScene.time);
		g.drawString(s, (d.width / 4) * 2 + this.margin, this.fm.getAscent()
				+ this.margin);

		// draw right tean name and score
		g.setColor(ColorDB.getColor("team_r_color"));
		g.fillRect((d.width / 4) * 3, 0, d.width, d.height);
		g.setColor(Color.black);
		s = this.clientScene.right.name + " :  " + this.clientScene.right.score;
		g.drawString(s, d.width - this.fm.stringWidth(s) - this.margin, this.fm
				.getAscent()
				+ this.margin);

		// draw border
		g.setColor(Color.black);
		g.drawRect(0, 0, d.width - 1, d.height - 1);
	}
}
